﻿namespace Access.Duoc
{
    using ConfigDatabase.Class;
    using Npgsql;
    using Access;
    using BaseClass.Duoc;
    using System;
    using System.Data;

    public class DBaoCaoDoanhThu
    {
        private ConnectDatabase _condata;
        private NpgsqlConnection _conn;
        private General _xuli;

        public DBaoCaoDoanhThu()
        {
            this._condata = new ConnectDatabase();
            this._xuli = new General(this._condata);
        }

        public DBaoCaoDoanhThu(ConnectDatabase condata)
        {
            this._condata = condata;
            this._xuli = new General(this._condata);
        }

        public DataTable f_loaddata_chitiet(string tungay, string denngay)
        {
            DataTable table = new DataTable();
            string str = this._condata.Schema + ".";
            string sql = "select b." + dtoDXuatBanLeCT.columnIDDUOCPHAM + " as idvp,b2." + dtoDDMDuocPham.columnTEN + " as tenvp,b2." + dtoDDMDuocPham.columnMA + " as mavp,b2." + dtoDDMDuocPham.columnDVT + " as dvt,sum(b." + dtoDXuatBanLeCT.columnSOLUONG + ") as soluong,b." + dtoDXuatBanLeCT.columnDONGIA + " as dongia,sum(b." + dtoDXuatBanLeCT.columnSOLUONG + " *b." + dtoDXuatBanLeCT.columnDONGIA + ") as thanhtien,sum(b." + dtoDXuatBanLeCT.columnSOLUONG + " *b." + dtoDXuatBanLeCT.columnDONGIA + ") as thucthu from " + str + dtoDXuatBanLe.tableName + " a inner join " + str + dtoDXuatBanLeCT.tableName + " b on a." + dtoDXuatBanLe.columnID + "=b." + dtoDXuatBanLeCT.columnIDXUATKHOBANLE + " inner join " + str + dtoDDMDuocPham.tableName + " b2 on b2." + dtoDDMDuocPham.columnID + "=b." + dtoDXuatBanLeCT.columnIDDUOCPHAM + " where 1=1 " + ((tungay != "") ? (" and to_timestamp(to_char(a." + dtoDXuatBanLe.columnNGAY + ",'dd/mm/yyyy'),'dd/mm/yyyy')>=to_timestamp('" + tungay + "','dd/mm/yyyy')") : "") + ((denngay != "") ? (" and to_timestamp(to_char(a." + dtoDXuatBanLe.columnNGAY + ",'dd/mm/yyyy'),'dd/mm/yyyy')<=to_timestamp('" + denngay + "','dd/mm/yyyy')") : "") + " group by b." + dtoDXuatBanLeCT.columnIDDUOCPHAM + ",b2." + dtoDDMDuocPham.columnTEN + ",b2." + dtoDDMDuocPham.columnMA + ",b2." + dtoDDMDuocPham.columnDVT + ",b." + dtoDXuatBanLeCT.columnDONGIA + " order by b2." + dtoDDMDuocPham.columnTEN + " desc";
            return this._xuli.f_Get_dulieu(sql).Tables[0];
        }

        private DataTable f_loaddata_thutien(long id, string tungay, string denngay, int loaithutien)
        {
            return new DataTable();
        }
    }
}

